n = int(input())
d = {}
for i in range(n):
    key, volume = input().split()
    d[key] = volume

word = input()
if word in d:
    print(d[word])
else:
    for k, v in d.items():
        if v == word:
            print(k)
            break